package catandmouse;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

public class GamePanel extends JPanel{

	private static final long serialVersionUID = 1L;


	private Coordinate mPos; //the mouse position
	private Coordinate cPos; //the cat position
	private CAM parent; //the SGP running the game panel
	private double count; //count used for time
	private int width; //the width of the panel
	private int height; //the height of the panel;

	//2 param constructor
	public GamePanel(Coordinate m, Coordinate c, CAM p, int w, int h){

		mPos = m;
		cPos = c;
		parent = p;
		count = 0;
		width = w;
		height = h;
		
		this.setFocusable(true);
		this.addKeyListener(parent);
	}//Coordinate, Coordinate, SingleGamePanel, int, int constructor


	//sets the mPos
	public void setMPos(Coordinate m){

		mPos = m;
	}//setMPos


	//sets the cPos
	public void setCPos(Coordinate c){

		cPos = c;
	}//setCPos


	//sets the count
	public void setCount(double c){

		count = c;
	}//setCount


	//overrides the default paint method to draw the panel
	public void paint(Graphics g) {


		//clears the screen
		g.clearRect(0, 0, width, height);

		//writes the current time in the middle
		g.setColor(Color.BLACK);
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 30));
		g.drawString(count / 100 + "s", width / 2,
				height/2);

		//draws the mouse
		int x = mPos.getX();
		int y = mPos.getY();

		g.setColor(Color.GREEN);
		g.fillRect(x - 5, y - 5, 10, 10);

		//draws the cat
		x = cPos.getX();
		y = cPos.getY();

		g.setColor(Color.RED);
		g.fillRect(x - 5, y - 5, 10, 10);
	}//paint
}//GamePanel
